<?php
if(function_exists('date_default_timezone_set')){ 
   date_default_timezone_set('America/Buenos_Aires');
}
 
session_start();

require_once "model/RequestHandler.php";
require_once "model/EntitlementValidator.php";
require_once "model/SmartyBuilder.php";
require_once "lib/Smarty/Smarty.class.php";

// get request information
$request_handler = new RequestHandler();
$controller_name = $request_handler->get_controller_name();
$controller_path = $request_handler->get_controller_path();
$action = $request_handler->get_action();

// validate needed entitlements for request
$entitlement_validator = new EntitlementValidator($request_handler);
if(!$entitlement_validator->has_entitlement()){
	session_destroy();
	header('location: /?request=public.login.initialize');
}

// include, instantiate and execute controller
require_once($controller_path);
$controller = new $controller_name();
$controller->$action();
$result_mapping = $controller->get_results();

// populate results and display template
$smarty = SmartyBuilder::build();
$smarty->assign($result_mapping);
$smarty->display($controller->get_template_path());

?>
